{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 10 Minutes to pandas\n",
    "请参阅[官方文档](http://pandas.pydata.org/pandas-docs/stable/10min.html)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 处理丢失数据\n",
    "\n",
    "Pandas 使用 numpy.NaN 来表示丢失的数据，它不参与计算。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 设置为 inline 风格\n",
    "%matplotlib inline\n",
    "# 包导入\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>-0.985666</td>\n",
       "      <td>0.240058</td>\n",
       "      <td>0.716721</td>\n",
       "      <td>0.352009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>-1.563644</td>\n",
       "      <td>0.091766</td>\n",
       "      <td>1.081764</td>\n",
       "      <td>0.951541</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>0.279760</td>\n",
       "      <td>-0.316136</td>\n",
       "      <td>1.198073</td>\n",
       "      <td>-0.562947</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>1.174777</td>\n",
       "      <td>-0.225305</td>\n",
       "      <td>-0.280256</td>\n",
       "      <td>-0.074768</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-05</th>\n",
       "      <td>2.173366</td>\n",
       "      <td>0.907038</td>\n",
       "      <td>-1.104678</td>\n",
       "      <td>-0.921779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-06</th>\n",
       "      <td>0.200422</td>\n",
       "      <td>0.442619</td>\n",
       "      <td>1.970330</td>\n",
       "      <td>-0.609867</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2016-03-01 -0.985666  0.240058  0.716721  0.352009\n",
       "2016-03-02 -1.563644  0.091766  1.081764  0.951541\n",
       "2016-03-03  0.279760 -0.316136  1.198073 -0.562947\n",
       "2016-03-04  1.174777 -0.225305 -0.280256 -0.074768\n",
       "2016-03-05  2.173366  0.907038 -1.104678 -0.921779\n",
       "2016-03-06  0.200422  0.442619  1.970330 -0.609867"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates = pd.date_range('20160301', periods=6)\n",
    "df = pd.DataFrame(data=np.random.randn(6, 4), index=dates, columns=list('ABCD'))\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>-0.985666</td>\n",
       "      <td>0.240058</td>\n",
       "      <td>0.716721</td>\n",
       "      <td>0.352009</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>-1.563644</td>\n",
       "      <td>0.091766</td>\n",
       "      <td>1.081764</td>\n",
       "      <td>0.951541</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>0.279760</td>\n",
       "      <td>-0.316136</td>\n",
       "      <td>1.198073</td>\n",
       "      <td>-0.562947</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>1.174777</td>\n",
       "      <td>-0.225305</td>\n",
       "      <td>-0.280256</td>\n",
       "      <td>-0.074768</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D   E\n",
       "2016-03-01 -0.985666  0.240058  0.716721  0.352009 NaN\n",
       "2016-03-02 -1.563644  0.091766  1.081764  0.951541 NaN\n",
       "2016-03-03  0.279760 -0.316136  1.198073 -0.562947 NaN\n",
       "2016-03-04  1.174777 -0.225305 -0.280256 -0.074768 NaN"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = df.reindex(index=dates[0:4], columns=list(df.columns) + ['E'])\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>-0.985666</td>\n",
       "      <td>0.240058</td>\n",
       "      <td>0.716721</td>\n",
       "      <td>0.352009</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>-1.563644</td>\n",
       "      <td>0.091766</td>\n",
       "      <td>1.081764</td>\n",
       "      <td>0.951541</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>0.279760</td>\n",
       "      <td>-0.316136</td>\n",
       "      <td>1.198073</td>\n",
       "      <td>-0.562947</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>1.174777</td>\n",
       "      <td>-0.225305</td>\n",
       "      <td>-0.280256</td>\n",
       "      <td>-0.074768</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D   E\n",
       "2016-03-01 -0.985666  0.240058  0.716721  0.352009 NaN\n",
       "2016-03-02 -1.563644  0.091766  1.081764  0.951541   1\n",
       "2016-03-03  0.279760 -0.316136  1.198073 -0.562947   1\n",
       "2016-03-04  1.174777 -0.225305 -0.280256 -0.074768 NaN"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.loc[dates[1:3], 'E'] = 1\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>-1.563644</td>\n",
       "      <td>0.091766</td>\n",
       "      <td>1.081764</td>\n",
       "      <td>0.951541</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>0.279760</td>\n",
       "      <td>-0.316136</td>\n",
       "      <td>1.198073</td>\n",
       "      <td>-0.562947</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D  E\n",
       "2016-03-02 -1.563644  0.091766  1.081764  0.951541  1\n",
       "2016-03-03  0.279760 -0.316136  1.198073 -0.562947  1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.dropna(how='any')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>-0.985666</td>\n",
       "      <td>0.240058</td>\n",
       "      <td>0.716721</td>\n",
       "      <td>0.352009</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>-1.563644</td>\n",
       "      <td>0.091766</td>\n",
       "      <td>1.081764</td>\n",
       "      <td>0.951541</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>0.279760</td>\n",
       "      <td>-0.316136</td>\n",
       "      <td>1.198073</td>\n",
       "      <td>-0.562947</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>1.174777</td>\n",
       "      <td>-0.225305</td>\n",
       "      <td>-0.280256</td>\n",
       "      <td>-0.074768</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D   E\n",
       "2016-03-01 -0.985666  0.240058  0.716721  0.352009 NaN\n",
       "2016-03-02 -1.563644  0.091766  1.081764  0.951541   1\n",
       "2016-03-03  0.279760 -0.316136  1.198073 -0.562947   1\n",
       "2016-03-04  1.174777 -0.225305 -0.280256 -0.074768 NaN"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>-0.985666</td>\n",
       "      <td>0.240058</td>\n",
       "      <td>0.716721</td>\n",
       "      <td>0.352009</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>-1.563644</td>\n",
       "      <td>0.091766</td>\n",
       "      <td>1.081764</td>\n",
       "      <td>0.951541</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>0.279760</td>\n",
       "      <td>-0.316136</td>\n",
       "      <td>1.198073</td>\n",
       "      <td>-0.562947</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>1.174777</td>\n",
       "      <td>-0.225305</td>\n",
       "      <td>-0.280256</td>\n",
       "      <td>-0.074768</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D  E\n",
       "2016-03-01 -0.985666  0.240058  0.716721  0.352009  5\n",
       "2016-03-02 -1.563644  0.091766  1.081764  0.951541  1\n",
       "2016-03-03  0.279760 -0.316136  1.198073 -0.562947  1\n",
       "2016-03-04  1.174777 -0.225305 -0.280256 -0.074768  5"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.fillna(value=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>-0.985666</td>\n",
       "      <td>0.240058</td>\n",
       "      <td>0.716721</td>\n",
       "      <td>0.352009</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>-1.563644</td>\n",
       "      <td>0.091766</td>\n",
       "      <td>1.081764</td>\n",
       "      <td>0.951541</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>0.279760</td>\n",
       "      <td>-0.316136</td>\n",
       "      <td>1.198073</td>\n",
       "      <td>-0.562947</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>1.174777</td>\n",
       "      <td>-0.225305</td>\n",
       "      <td>-0.280256</td>\n",
       "      <td>-0.074768</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D   E\n",
       "2016-03-01 -0.985666  0.240058  0.716721  0.352009 NaN\n",
       "2016-03-02 -1.563644  0.091766  1.081764  0.951541   1\n",
       "2016-03-03  0.279760 -0.316136  1.198073 -0.562947   1\n",
       "2016-03-04  1.174777 -0.225305 -0.280256 -0.074768 NaN"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                A      B      C      D      E\n",
       "2016-03-01  False  False  False  False   True\n",
       "2016-03-02  False  False  False  False  False\n",
       "2016-03-03  False  False  False  False  False\n",
       "2016-03-04  False  False  False  False   True"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.isnull(df1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 统计\n",
    "\n",
    "numpy.NaN 不参与计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A   -0.273693\n",
       "B   -0.052404\n",
       "C    0.679076\n",
       "D    0.166459\n",
       "E    1.000000\n",
       "dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2016-03-01    0.080781\n",
       "2016-03-02    0.312285\n",
       "2016-03-03    0.319750\n",
       "2016-03-04    0.148612\n",
       "Freq: D, dtype: float64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.mean(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2016-03-01    0.080781\n",
       "2016-03-02    0.140357\n",
       "2016-03-03    0.149687\n",
       "2016-03-04    0.148612\n",
       "2016-03-05    0.263487\n",
       "2016-03-06    0.500876\n",
       "Freq: D, dtype: float64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.mean(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    1.279015\n",
       "B    1.140040\n",
       "C    3.581954\n",
       "D   -0.865811\n",
       "dtype: float64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2016-03-01    0.323123\n",
       "2016-03-02    0.561427\n",
       "2016-03-03    0.598749\n",
       "2016-03-04    0.594449\n",
       "2016-03-05    1.053947\n",
       "2016-03-06    2.003504\n",
       "Freq: D, dtype: float64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sum(axis='columns')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>-0.985666</td>\n",
       "      <td>0.240058</td>\n",
       "      <td>0.716721</td>\n",
       "      <td>0.352009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>-2.549311</td>\n",
       "      <td>0.331824</td>\n",
       "      <td>1.798486</td>\n",
       "      <td>1.303550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>-2.269551</td>\n",
       "      <td>0.015688</td>\n",
       "      <td>2.996558</td>\n",
       "      <td>0.740602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>-1.094774</td>\n",
       "      <td>-0.209616</td>\n",
       "      <td>2.716302</td>\n",
       "      <td>0.665835</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-05</th>\n",
       "      <td>1.078593</td>\n",
       "      <td>0.697421</td>\n",
       "      <td>1.611624</td>\n",
       "      <td>-0.255944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-06</th>\n",
       "      <td>1.279015</td>\n",
       "      <td>1.140040</td>\n",
       "      <td>3.581954</td>\n",
       "      <td>-0.865811</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2016-03-01 -0.985666  0.240058  0.716721  0.352009\n",
       "2016-03-02 -2.549311  0.331824  1.798486  1.303550\n",
       "2016-03-03 -2.269551  0.015688  2.996558  0.740602\n",
       "2016-03-04 -1.094774 -0.209616  2.716302  0.665835\n",
       "2016-03-05  1.078593  0.697421  1.611624 -0.255944\n",
       "2016-03-06  1.279015  1.140040  3.581954 -0.865811"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cumsum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2016-03-01   NaN\n",
       "2016-03-02   NaN\n",
       "2016-03-03     1\n",
       "2016-03-04     3\n",
       "2016-03-05     5\n",
       "2016-03-06   NaN\n",
       "Freq: D, dtype: float64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.Series([1,3,5,np.nan,6,8], index=dates).shift(2)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>-0.985666</td>\n",
       "      <td>0.240058</td>\n",
       "      <td>0.716721</td>\n",
       "      <td>0.352009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>-1.563644</td>\n",
       "      <td>0.091766</td>\n",
       "      <td>1.081764</td>\n",
       "      <td>0.951541</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>0.279760</td>\n",
       "      <td>-0.316136</td>\n",
       "      <td>1.198073</td>\n",
       "      <td>-0.562947</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>1.174777</td>\n",
       "      <td>-0.225305</td>\n",
       "      <td>-0.280256</td>\n",
       "      <td>-0.074768</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-05</th>\n",
       "      <td>2.173366</td>\n",
       "      <td>0.907038</td>\n",
       "      <td>-1.104678</td>\n",
       "      <td>-0.921779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-06</th>\n",
       "      <td>0.200422</td>\n",
       "      <td>0.442619</td>\n",
       "      <td>1.970330</td>\n",
       "      <td>-0.609867</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2016-03-01 -0.985666  0.240058  0.716721  0.352009\n",
       "2016-03-02 -1.563644  0.091766  1.081764  0.951541\n",
       "2016-03-03  0.279760 -0.316136  1.198073 -0.562947\n",
       "2016-03-04  1.174777 -0.225305 -0.280256 -0.074768\n",
       "2016-03-05  2.173366  0.907038 -1.104678 -0.921779\n",
       "2016-03-06  0.200422  0.442619  1.970330 -0.609867"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>-0.720240</td>\n",
       "      <td>-1.316136</td>\n",
       "      <td>0.198073</td>\n",
       "      <td>-1.562947</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>-1.825223</td>\n",
       "      <td>-3.225305</td>\n",
       "      <td>-3.280256</td>\n",
       "      <td>-3.074768</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-05</th>\n",
       "      <td>-2.826634</td>\n",
       "      <td>-4.092962</td>\n",
       "      <td>-6.104678</td>\n",
       "      <td>-5.921779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-06</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2016-03-01       NaN       NaN       NaN       NaN\n",
       "2016-03-02       NaN       NaN       NaN       NaN\n",
       "2016-03-03 -0.720240 -1.316136  0.198073 -1.562947\n",
       "2016-03-04 -1.825223 -3.225305 -3.280256 -3.074768\n",
       "2016-03-05 -2.826634 -4.092962 -6.104678 -5.921779\n",
       "2016-03-06       NaN       NaN       NaN       NaN"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sub(s, axis='index')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2016-03-01</th>\n",
       "      <td>-0.985666</td>\n",
       "      <td>0.240058</td>\n",
       "      <td>0.716721</td>\n",
       "      <td>0.352009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-02</th>\n",
       "      <td>-2.549311</td>\n",
       "      <td>0.331824</td>\n",
       "      <td>1.798486</td>\n",
       "      <td>1.303550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-03</th>\n",
       "      <td>-2.269551</td>\n",
       "      <td>0.015688</td>\n",
       "      <td>2.996558</td>\n",
       "      <td>0.740602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-04</th>\n",
       "      <td>-1.094774</td>\n",
       "      <td>-0.209616</td>\n",
       "      <td>2.716302</td>\n",
       "      <td>0.665835</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-05</th>\n",
       "      <td>1.078593</td>\n",
       "      <td>0.697421</td>\n",
       "      <td>1.611624</td>\n",
       "      <td>-0.255944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-03-06</th>\n",
       "      <td>1.279015</td>\n",
       "      <td>1.140040</td>\n",
       "      <td>3.581954</td>\n",
       "      <td>-0.865811</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A         B         C         D\n",
       "2016-03-01 -0.985666  0.240058  0.716721  0.352009\n",
       "2016-03-02 -2.549311  0.331824  1.798486  1.303550\n",
       "2016-03-03 -2.269551  0.015688  2.996558  0.740602\n",
       "2016-03-04 -1.094774 -0.209616  2.716302  0.665835\n",
       "2016-03-05  1.078593  0.697421  1.611624 -0.255944\n",
       "2016-03-06  1.279015  1.140040  3.581954 -0.865811"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.apply(np.cumsum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    3.737010\n",
       "B    1.223174\n",
       "C    3.075008\n",
       "D    1.873320\n",
       "dtype: float64"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.apply(lambda x: x.max() - x.min())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    4\n",
       "3    2\n",
       "4    1\n",
       "5    3\n",
       "6    1\n",
       "7    2\n",
       "8    4\n",
       "9    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.Series(np.random.randint(0, 7, size=10))\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2    3\n",
       "1    3\n",
       "4    2\n",
       "3    2\n",
       "dtype: int64"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "dtype: int64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.mode()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.098103</td>\n",
       "      <td>-0.843356</td>\n",
       "      <td>-0.379135</td>\n",
       "      <td>0.419353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.177702</td>\n",
       "      <td>-0.225926</td>\n",
       "      <td>-0.363542</td>\n",
       "      <td>-0.153022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.938231</td>\n",
       "      <td>0.154881</td>\n",
       "      <td>0.291382</td>\n",
       "      <td>0.152774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.460645</td>\n",
       "      <td>-0.268697</td>\n",
       "      <td>-1.509469</td>\n",
       "      <td>0.698776</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.397048</td>\n",
       "      <td>-0.958223</td>\n",
       "      <td>0.212833</td>\n",
       "      <td>-0.435485</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.525406</td>\n",
       "      <td>-0.177595</td>\n",
       "      <td>0.453216</td>\n",
       "      <td>-0.093792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.531912</td>\n",
       "      <td>-0.832667</td>\n",
       "      <td>0.200721</td>\n",
       "      <td>0.943878</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.740845</td>\n",
       "      <td>0.098634</td>\n",
       "      <td>0.274020</td>\n",
       "      <td>1.671997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2.182379</td>\n",
       "      <td>1.729010</td>\n",
       "      <td>1.306269</td>\n",
       "      <td>0.580677</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.031538</td>\n",
       "      <td>0.159714</td>\n",
       "      <td>0.736667</td>\n",
       "      <td>-0.122326</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B         C         D\n",
       "0  1.098103 -0.843356 -0.379135  0.419353\n",
       "1 -0.177702 -0.225926 -0.363542 -0.153022\n",
       "2  1.938231  0.154881  0.291382  0.152774\n",
       "3 -0.460645 -0.268697 -1.509469  0.698776\n",
       "4 -0.397048 -0.958223  0.212833 -0.435485\n",
       "5  0.525406 -0.177595  0.453216 -0.093792\n",
       "6  0.531912 -0.832667  0.200721  0.943878\n",
       "7 -0.740845  0.098634  0.274020  1.671997\n",
       "8  2.182379  1.729010  1.306269  0.580677\n",
       "9 -0.031538  0.159714  0.736667 -0.122326"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(np.random.randn(10, 4), columns=list('ABCD'))\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.098103</td>\n",
       "      <td>-0.843356</td>\n",
       "      <td>-0.379135</td>\n",
       "      <td>0.419353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.177702</td>\n",
       "      <td>-0.225926</td>\n",
       "      <td>-0.363542</td>\n",
       "      <td>-0.153022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.938231</td>\n",
       "      <td>0.154881</td>\n",
       "      <td>0.291382</td>\n",
       "      <td>0.152774</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B         C         D\n",
       "0  1.098103 -0.843356 -0.379135  0.419353\n",
       "1 -0.177702 -0.225926 -0.363542 -0.153022\n",
       "2  1.938231  0.154881  0.291382  0.152774"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.460645</td>\n",
       "      <td>-0.268697</td>\n",
       "      <td>-1.509469</td>\n",
       "      <td>0.698776</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.397048</td>\n",
       "      <td>-0.958223</td>\n",
       "      <td>0.212833</td>\n",
       "      <td>-0.435485</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.525406</td>\n",
       "      <td>-0.177595</td>\n",
       "      <td>0.453216</td>\n",
       "      <td>-0.093792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.531912</td>\n",
       "      <td>-0.832667</td>\n",
       "      <td>0.200721</td>\n",
       "      <td>0.943878</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B         C         D\n",
       "3 -0.460645 -0.268697 -1.509469  0.698776\n",
       "4 -0.397048 -0.958223  0.212833 -0.435485\n",
       "5  0.525406 -0.177595  0.453216 -0.093792\n",
       "6  0.531912 -0.832667  0.200721  0.943878"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[3:7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.740845</td>\n",
       "      <td>0.098634</td>\n",
       "      <td>0.274020</td>\n",
       "      <td>1.671997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2.182379</td>\n",
       "      <td>1.729010</td>\n",
       "      <td>1.306269</td>\n",
       "      <td>0.580677</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.031538</td>\n",
       "      <td>0.159714</td>\n",
       "      <td>0.736667</td>\n",
       "      <td>-0.122326</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B         C         D\n",
       "7 -0.740845  0.098634  0.274020  1.671997\n",
       "8  2.182379  1.729010  1.306269  0.580677\n",
       "9 -0.031538  0.159714  0.736667 -0.122326"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[7:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.098103</td>\n",
       "      <td>-0.843356</td>\n",
       "      <td>-0.379135</td>\n",
       "      <td>0.419353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.177702</td>\n",
       "      <td>-0.225926</td>\n",
       "      <td>-0.363542</td>\n",
       "      <td>-0.153022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.938231</td>\n",
       "      <td>0.154881</td>\n",
       "      <td>0.291382</td>\n",
       "      <td>0.152774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.460645</td>\n",
       "      <td>-0.268697</td>\n",
       "      <td>-1.509469</td>\n",
       "      <td>0.698776</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.397048</td>\n",
       "      <td>-0.958223</td>\n",
       "      <td>0.212833</td>\n",
       "      <td>-0.435485</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.525406</td>\n",
       "      <td>-0.177595</td>\n",
       "      <td>0.453216</td>\n",
       "      <td>-0.093792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.531912</td>\n",
       "      <td>-0.832667</td>\n",
       "      <td>0.200721</td>\n",
       "      <td>0.943878</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.740845</td>\n",
       "      <td>0.098634</td>\n",
       "      <td>0.274020</td>\n",
       "      <td>1.671997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2.182379</td>\n",
       "      <td>1.729010</td>\n",
       "      <td>1.306269</td>\n",
       "      <td>0.580677</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.031538</td>\n",
       "      <td>0.159714</td>\n",
       "      <td>0.736667</td>\n",
       "      <td>-0.122326</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B         C         D\n",
       "0  1.098103 -0.843356 -0.379135  0.419353\n",
       "1 -0.177702 -0.225926 -0.363542 -0.153022\n",
       "2  1.938231  0.154881  0.291382  0.152774\n",
       "3 -0.460645 -0.268697 -1.509469  0.698776\n",
       "4 -0.397048 -0.958223  0.212833 -0.435485\n",
       "5  0.525406 -0.177595  0.453216 -0.093792\n",
       "6  0.531912 -0.832667  0.200721  0.943878\n",
       "7 -0.740845  0.098634  0.274020  1.671997\n",
       "8  2.182379  1.729010  1.306269  0.580677\n",
       "9 -0.031538  0.159714  0.736667 -0.122326"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = pd.concat([df.iloc[:3], df.iloc[3:7], df.iloc[7:]])\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(df1 == df).all().all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# SQL 样式的联合查询\n",
    "left = pd.DataFrame({'key': ['foo', 'foo'], 'lval': [1, 2]})\n",
    "right = pd.DataFrame({'key': ['foo', 'foo'], 'rval': [4, 5]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key</th>\n",
       "      <th>lval</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>foo</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>foo</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   key  lval\n",
       "0  foo     1\n",
       "1  foo     2"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "left"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key</th>\n",
       "      <th>rval</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>foo</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>foo</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   key  rval\n",
       "0  foo     4\n",
       "1  foo     5"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "right"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key</th>\n",
       "      <th>lval</th>\n",
       "      <th>rval</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>foo</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>foo</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>foo</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>foo</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   key  lval  rval\n",
       "0  foo     1     4\n",
       "1  foo     1     5\n",
       "2  foo     2     4\n",
       "3  foo     2     5"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# SELECT * FROM left INNER JOIN right ON left.key = right.key;\n",
    "pd.merge(left, right, on='key')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.098103</td>\n",
       "      <td>-0.843356</td>\n",
       "      <td>-0.379135</td>\n",
       "      <td>0.419353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.177702</td>\n",
       "      <td>-0.225926</td>\n",
       "      <td>-0.363542</td>\n",
       "      <td>-0.153022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.938231</td>\n",
       "      <td>0.154881</td>\n",
       "      <td>0.291382</td>\n",
       "      <td>0.152774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.460645</td>\n",
       "      <td>-0.268697</td>\n",
       "      <td>-1.509469</td>\n",
       "      <td>0.698776</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.397048</td>\n",
       "      <td>-0.958223</td>\n",
       "      <td>0.212833</td>\n",
       "      <td>-0.435485</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.525406</td>\n",
       "      <td>-0.177595</td>\n",
       "      <td>0.453216</td>\n",
       "      <td>-0.093792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.531912</td>\n",
       "      <td>-0.832667</td>\n",
       "      <td>0.200721</td>\n",
       "      <td>0.943878</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.740845</td>\n",
       "      <td>0.098634</td>\n",
       "      <td>0.274020</td>\n",
       "      <td>1.671997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2.182379</td>\n",
       "      <td>1.729010</td>\n",
       "      <td>1.306269</td>\n",
       "      <td>0.580677</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.031538</td>\n",
       "      <td>0.159714</td>\n",
       "      <td>0.736667</td>\n",
       "      <td>-0.122326</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B         C         D\n",
       "0  1.098103 -0.843356 -0.379135  0.419353\n",
       "1 -0.177702 -0.225926 -0.363542 -0.153022\n",
       "2  1.938231  0.154881  0.291382  0.152774\n",
       "3 -0.460645 -0.268697 -1.509469  0.698776\n",
       "4 -0.397048 -0.958223  0.212833 -0.435485\n",
       "5  0.525406 -0.177595  0.453216 -0.093792\n",
       "6  0.531912 -0.832667  0.200721  0.943878\n",
       "7 -0.740845  0.098634  0.274020  1.671997\n",
       "8  2.182379  1.729010  1.306269  0.580677\n",
       "9 -0.031538  0.159714  0.736667 -0.122326"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.098103</td>\n",
       "      <td>-0.843356</td>\n",
       "      <td>-0.379135</td>\n",
       "      <td>0.419353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.177702</td>\n",
       "      <td>-0.225926</td>\n",
       "      <td>-0.363542</td>\n",
       "      <td>-0.153022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.938231</td>\n",
       "      <td>0.154881</td>\n",
       "      <td>0.291382</td>\n",
       "      <td>0.152774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.460645</td>\n",
       "      <td>-0.268697</td>\n",
       "      <td>-1.509469</td>\n",
       "      <td>0.698776</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-0.397048</td>\n",
       "      <td>-0.958223</td>\n",
       "      <td>0.212833</td>\n",
       "      <td>-0.435485</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.525406</td>\n",
       "      <td>-0.177595</td>\n",
       "      <td>0.453216</td>\n",
       "      <td>-0.093792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.531912</td>\n",
       "      <td>-0.832667</td>\n",
       "      <td>0.200721</td>\n",
       "      <td>0.943878</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.740845</td>\n",
       "      <td>0.098634</td>\n",
       "      <td>0.274020</td>\n",
       "      <td>1.671997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2.182379</td>\n",
       "      <td>1.729010</td>\n",
       "      <td>1.306269</td>\n",
       "      <td>0.580677</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.031538</td>\n",
       "      <td>0.159714</td>\n",
       "      <td>0.736667</td>\n",
       "      <td>-0.122326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>4.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           A         B         C         D\n",
       "0   1.098103 -0.843356 -0.379135  0.419353\n",
       "1  -0.177702 -0.225926 -0.363542 -0.153022\n",
       "2   1.938231  0.154881  0.291382  0.152774\n",
       "3  -0.460645 -0.268697 -1.509469  0.698776\n",
       "4  -0.397048 -0.958223  0.212833 -0.435485\n",
       "5   0.525406 -0.177595  0.453216 -0.093792\n",
       "6   0.531912 -0.832667  0.200721  0.943878\n",
       "7  -0.740845  0.098634  0.274020  1.671997\n",
       "8   2.182379  1.729010  1.306269  0.580677\n",
       "9  -0.031538  0.159714  0.736667 -0.122326\n",
       "10  4.000000  4.000000  4.000000  2.000000"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.Series(np.random.randint(1, 5, size=4), index=list('ABCD'))\n",
    "df.append(s, ignore_index=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 分组统计\n",
    "\n",
    "* 数据分组\n",
    "* 每个组应用一个函数，输出一个结果\n",
    "* 合并每个组的结果构成最终输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>foo</td>\n",
       "      <td>one</td>\n",
       "      <td>-0.580320</td>\n",
       "      <td>-1.460149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bar</td>\n",
       "      <td>one</td>\n",
       "      <td>1.471201</td>\n",
       "      <td>-1.079598</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>foo</td>\n",
       "      <td>two</td>\n",
       "      <td>0.094836</td>\n",
       "      <td>1.513204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>bar</td>\n",
       "      <td>three</td>\n",
       "      <td>-1.498810</td>\n",
       "      <td>0.754968</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>foo</td>\n",
       "      <td>two</td>\n",
       "      <td>0.180709</td>\n",
       "      <td>0.415266</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>bar</td>\n",
       "      <td>two</td>\n",
       "      <td>0.358515</td>\n",
       "      <td>-0.341988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>foo</td>\n",
       "      <td>one</td>\n",
       "      <td>-0.121082</td>\n",
       "      <td>-0.408148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>foo</td>\n",
       "      <td>three</td>\n",
       "      <td>0.404648</td>\n",
       "      <td>-0.320882</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A      B         C         D\n",
       "0  foo    one -0.580320 -1.460149\n",
       "1  bar    one  1.471201 -1.079598\n",
       "2  foo    two  0.094836  1.513204\n",
       "3  bar  three -1.498810  0.754968\n",
       "4  foo    two  0.180709  0.415266\n",
       "5  bar    two  0.358515 -0.341988\n",
       "6  foo    one -0.121082 -0.408148\n",
       "7  foo  three  0.404648 -0.320882"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar',\n",
    "                          'foo', 'bar', 'foo', 'foo'],\n",
    "                   'B' : ['one', 'one', 'two', 'three',\n",
    "                           'two', 'two', 'one', 'three'],\n",
    "                   'C' : np.random.randn(8),\n",
    "                   'D' : np.random.randn(8)})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>bar</th>\n",
       "      <td>0.330906</td>\n",
       "      <td>-0.666618</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>foo</th>\n",
       "      <td>-0.021208</td>\n",
       "      <td>-0.260709</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            C         D\n",
       "A                      \n",
       "bar  0.330906 -0.666618\n",
       "foo -0.021208 -0.260709"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('A').sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">bar</th>\n",
       "      <th>one</th>\n",
       "      <td>1.471201</td>\n",
       "      <td>-1.079598</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>three</th>\n",
       "      <td>-1.498810</td>\n",
       "      <td>0.754968</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>0.358515</td>\n",
       "      <td>-0.341988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">foo</th>\n",
       "      <th>one</th>\n",
       "      <td>-0.701402</td>\n",
       "      <td>-1.868297</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>three</th>\n",
       "      <td>0.404648</td>\n",
       "      <td>-0.320882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>0.275545</td>\n",
       "      <td>1.928470</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  C         D\n",
       "A   B                        \n",
       "bar one    1.471201 -1.079598\n",
       "    three -1.498810  0.754968\n",
       "    two    0.358515 -0.341988\n",
       "foo one   -0.701402 -1.868297\n",
       "    three  0.404648 -0.320882\n",
       "    two    0.275545  1.928470"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df.groupby(['B', 'A']).sum()\n",
    "df.groupby(['A', 'B']).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
